<template>
  <div>

     <el-form ref="form" :model="query" label-width="80px" :inline="true">
        <el-form-item>
          <el-input
            v-model="query.kw"
            clearable
            placeholder="手机号/昵称"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSearch()">搜索</el-button>
        </el-form-item>
      </el-form>

      <el-table :data="dataList" border >
        <el-table-column label="编号" prop="id"></el-table-column>
        <el-table-column label="用户名" prop="username"></el-table-column>
        <el-table-column label="手机号" prop="tel"></el-table-column>
        <el-table-column label="性别" prop="sex">
          <template slot-scope="scope">
            {{scope.row.sex == 1? '男':(scope.row.sex == 2?'女':'--')}}
          </template>
        </el-table-column>
        <el-table-column label="状态" prop="status">
          <template slot-scope="scope">
            {{scope.row.status == 1?'通过':(scope.row.status == 2?'拒绝':'待审')}}
          </template>
        </el-table-column>
        <el-table-column label="创建时间" prop="createtime" width="150px">
          <template slot-scope="scope">
            {{formattime(scope.row.createtime)}}
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        :total="total"
        :current-page="query.page"
        :page-size="10"
        @current-change="changePage"
      ></el-pagination>


  </div>
</template>

<script>
 import {deviceuserpage} from "@/api/equipment/index.js"
 import moment from 'moment'
  export default {
    props:['deviceid'],
    watch:{
      deviceid:{
        handler:function(val){
          this.query.page = 1;
          this.query.device_id = val;
          this.query.kw = ''
          this.getData()
        },
        immediate:true,
      }
    },
    data(){
      return {
        query:{
          page:1,
          device_id:'',
          kw:''
        },
        dataList:[],
        total:0,
      }
    },
    methods:{
      getData(){
        deviceuserpage(this.query).then(res=>{
          this.total = res.data.total
          this.dataList = res.data.data
        })
      },
      formattime(time){
        return moment(time*1000).format("YYYY-MM-DD HH:mm:ss")
      },
      changePage(page){
        this.query.page = page;
        this.getData()
      },
      onSearch(){
        this.query.page = 1
        this.getData()
      }
    }
  }
</script>

<style scoped>

</style>